package com.hyk.commonLib.common.utils.luban;

import android.graphics.Bitmap;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import top.zibin.luban.InputStreamProvider;

/**
 * Created by 贺玉琨 on 2019/9/13.
 */
public class BitmapProvider implements InputStreamProvider {
    private final Bitmap bitmap;
    private final String path;

    public BitmapProvider(Bitmap bitmap, String path) {
        this.bitmap = bitmap;
        this.path = path;
    }

    @Override
    public InputStream open() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
        return new ByteArrayInputStream(baos.toByteArray());
    }

    @Override
    public String getPath() {
        return path;
    }
}
